import { Typography } from "antd";
import { ParagraphProps } from "antd/lib/typography/Paragraph";
interface IEllipsisMiddle extends ParagraphProps {
  suffixCount?: number //自定义省略内容后缀长度
  children: string
  rows?: number //显示行数
}

//字符串中间省略组件
const EllipsisMiddle: React.FC<IEllipsisMiddle> = (props) => {
  const { suffixCount = 7, children = '', rows, ...other } = props
  let start = children.slice(0, children.length - suffixCount).trim();
  let suffix = children.slice(-suffixCount).trim();
  if (children.length < suffixCount) {
    start = children
    suffix = ''
  }
  return (
    <Typography.Paragraph {...other} ellipsis={{ suffix, rows }}>
      {start}
    </Typography.Paragraph>
  );
}

EllipsisMiddle.defaultProps = {
  rows: 2,
  suffixCount: 7
}

export default EllipsisMiddle